﻿(function (wtm) {
    wtm.linkbutton_Render = function (para) {
        var $el = $('#' + para.id);

        $el.on('click', function () {
            if (para.confirmTxt.length > 0) {
                layui.layer.confirm(para.confirmTxt, { icon: 3, title: para.info }, function (index) {
                    wtm.linkbutton_Open(para);
                });
            }
            else {
                wtm.linkbutton_Open(para);
            }
        });

    };

    wtm.linkbutton_Open = function (para) {
        if (para.type == '' || para.type == 'layer') {
            ff.OpenDialog(para.url, para.id, para.title, 'null', 'null', para.data);
        } else if (para.type == 'self') {
            wtm.linkbutton_BgRequest({
                url: para.url,
                data: para.data,
                divid: para.divId
            });
        } else if (para.type == 'newwindow') {
            if (para.isPublic) {
                ff.SetCookie('#' + para.url, para.title, true);
                console.log(1);
                window.open('/Home/PIndex#' + para.url);
            } else {
                ff.SetCookie('#' + para.url, para.title, true);
                console.log(2);
                window.open(para.url);
            }
        } else if (para.type == 'currentwindow') {
            ff.LoadPage(para.url, false, para.title);
        }
    };


    wtm.linkbutton_BgRequest = function (obj) {
        var layer = layui.layer;
        var index = layer.load(2);

        var getpost = "GET";
        if (obj.data !== undefined) {
            getpost = "Post";
        }

        $.ajax({
            cache: false,
            type: getpost,
            url: obj.url,
            data: obj.data,
            async: true,
            error: function (request) {
                layer.close(index);
                alert(ff.DONOTUSE_Text_SubmitFailed);
            },
            success: function (data, textStatus, request) {
                if (request.getResponseHeader('IsScript') === 'true') {
                    eval(data);
                }
                else {
                    var inlayer = $("#" + obj.divid).parents(".layui-layer-content");
                    if (inlayer !== undefined && inlayer.length > 0) {
                        data = "<div id='" + $.cookie("divid") + "' class='donotuse_pdiv'>" + data + "</div>";
                    } else {
                        data = "<div id='" + $.cookie("divid") + "' class='layui-card-body donotuse_pdiv'>" + data + "</div>";
                    }
                    $("#" + obj.divid).parent().html(data);
                }
                layer.close(index);
            }
        });
    };



})(wtm);